package ${package.Controller};

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import ${package.Service}.I${entity}Service;
import ${package.Service}.model.response.Result;
import ${package.Service?substring(0,package.Service?last_index_of(".service"))}.model.response.RowData;

import com.yuntun.sanitationkitchen.auth.Limit;
import com.yuntun.sanitationkitchen.auth.UserIdHolder;
import com.yuntun.sanitationkitchen.exception.ServiceException;
import com.yuntun.sanitationkitchen.model.entity.${entity};
import com.yuntun.sanitationkitchen.model.response.Result;
import com.yuntun.sanitationkitchen.model.response.RowData;
import com.yuntun.sanitationkitchen.model.vo.VehicleListVo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yuntun.sanitationkitchen.util.EptUtil;
import com.yuntun.sanitationkitchen.util.ErrorUtil;
import com.yuntun.sanitationkitchen.util.ListUtil;
import com.yuntun.sanitationkitchen.util.SnowflakeUtil;
/**
* <p>
    * ${table.comment!} 前端控制器
    * </p>
*
* @author ${author}
* @since ${date}
*/
@RestController
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
@Slf4j
public class ${table.controllerName}{

    @Autowired
    I${entity}Service i${entity}Service;

    @Limit("${entity}:list")
    @GetMapping("/list")
    public Result<Object> list(VehicleListDto dto) {

        ErrorUtil.PageParamError(dto.getPageSize(), dto.getPageNo());

        IPage<${entity}> iPage = i${entity}Service.page(
            new Page<${entity}>().setSize(dto.getPageSize()).setCurrent(dto.getPageNo()),
            new QueryWrapper<${entity}>().orderByDesc("create_time")

        );

        List<${entity}ListVo> vos = ListUtil.listMap(${entity}ListVo.class, iPage.getRecords());
        RowData<${entity}ListVo> data = new RowData<${entity}ListVo>() .setRows(vos) .setTotal(iPage.getTotal()).setTotalPages(iPage.getTotal());
        return Result.ok(data);
    }
    @Data
    @Accessors(chain = true)
    public static class ${entity}ListDto{
        Integer pageSize;
        Integer pageNo;
        <#-- ----------  BEGIN 字段循环遍历  ---------->
        <#list table.fields as field>
            <#if field.comment!?length gt 0>
            /**
            * ${field.comment}
            */
            </#if>
            private ${field.propertyType} ${field.propertyName};
        </#list>

    }

    @Data
    @Accessors(chain = true)
    public static class ${entity}ListVo{
    Integer pageSize;
    Integer pageNo;
    <#-- ----------  BEGIN 字段循环遍历  ---------->
    <#list table.fields as field>
        <#if field.comment!?length gt 0>
            /**
            * ${field.comment}
            */
        </#if>
        private ${field.propertyType} ${field.propertyName};
    </#list>

    }

    @Data
    @Accessors(chain = true)
    public static class ${entity}GetVo{
    Integer pageSize;
    Integer pageNo;
    <#-- ----------  BEGIN 字段循环遍历  ---------->
    <#list table.fields as field>
        <#if field.comment!?length gt 0>
            /**
            * ${field.comment}
            */
        </#if>
        private ${field.propertyType} ${field.propertyName};
    </#list>

    }

    @Data
    @Accessors(chain = true)
    public static class ${entity}SaveDto{
    <#-- ----------  BEGIN 字段循环遍历  ---------->
    <#list table.fields as field>
        <#if field.comment!?length gt 0>
            /**
            * ${field.comment}
            */
        </#if>
        private ${field.propertyType} ${field.propertyName};
    </#list>

    }

    @Data
    @Accessors(chain = true)
    public static class ${entity}UpdateDto{
    <#-- ----------  BEGIN 字段循环遍历  ---------->
    <#list table.fields as field>
        <#if field.comment!?length gt 0>
            /**
            * ${field.comment}
            */
        </#if>
        private ${field.propertyType} ${field.propertyName};
    </#list>

    }

}

